package com.bentley.kotlindemo.ui.kits.bottomtab

import android.os.Bundle
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI.setupActionBarWithNavController
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import com.bentley.kotlindemo.R
import com.bentley.kotlindemo.base.BaseActivity
import com.bentley.kotlindemo.databinding.ActivityBottomtabBinding
import com.google.android.material.bottomnavigation.BottomNavigationView

/**
 * <pre>
 *  ┌────────────────────────────────────────────
 *  │ @author  Lee  @date 2021/3/26 14:16
 *  ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
 *  │ @desc 底部按钮
 *  └────────────────────────────────────────────
 * </pre>
 */
class BottomTabActivity :BaseActivity<ActivityBottomtabBinding,BottomTabModel>(){
    override fun initView(savedInstanceState: Bundle?) {


//        val navController = findNavController(R.id.nav_host_fragment)
//        val appBarConfiguration = AppBarConfiguration(
//            setOf(
//                R.id.home,
//                R.id.blog
//            )
//        )
//        setupActionBarWithNavController(navController, appBarConfiguration)
//        dataBinding.navView.setupWithNavController(navController)
//        dataBinding.navView.getOrCreateBadge(R.id.navigation_movie)?.number = 2


        val navView: BottomNavigationView = findViewById(R.id.nav_view)
        val navController = findNavController(R.id.nav_host_fragment)
        navView.setupWithNavController(navController)

        val badge = navView.getOrCreateBadge(R.id.home)
        badge.number = 20

        navView.setOnNavigationItemSelectedListener(onNavigationItemSelected)
    }

    private val onNavigationItemSelected = BottomNavigationView.OnNavigationItemSelectedListener {
        when (it.itemId) {
            R.id.home -> {
//                switchFragment(0)
                findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_music)
            }
            R.id.blog -> {
                findNavController(R.id.nav_host_fragment).navigate(R.id.navigation_movie)
            }

        }
        true
    }

//    private fun switchFragment(position: Int): Boolean {
////        mainViewpager.currentItem = position
//        mainViewpager.setCurrentItem(position, false)
//        return true
//    }

    override fun getLayoutId(): Int = R.layout.activity_bottomtab
}